DataType (Apache Ant API)

org.apache.tools.ant.types

## Class DataType

- java.lang.Object
- - org.apache.tools.ant.ProjectComponent
  - - org.apache.tools.ant.types.DataType

- All Implemented Interfaces:
    java.lang.Cloneable
  Direct Known Subclasses:
    AbstractFileSet, AbstractResourceCollectionWrapper, AbstractSelectorContainer, AntFilterReader, Archives, Assertions, BaseResourceCollectionContainer, BaseSelector, Compare, Description, ExtensionAdapter, ExtensionSet, FileList, FilterChain, FilterSet, ImageOperation, IsSigned, MappedResourceCollection, Mapper, Path, PatternSet, PropertySet, RedirectorElement, RegularExpression, Resource, ResourceComparator, ResourceList, Resources, ResourceSelectorContainer, SignedSelector, Substitution, XMLCatalog

      public abstract class DataType
      extends ProjectComponent
      implements java.lang.Cloneable

  Base class for those classes that can appear inside the build file as stand alone data types.

  This class handles the common description attribute and provides a default implementation for reference handling and checking for circular references that is appropriate for types that can not be nested inside elements of the same type (i.e. <patternset> but not <path>).

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `protected boolean` | `checked` Deprecated. since 1.7. The user should not be directly referencing variable. Please use `setChecked(boolean)` or `isChecked()` instead.
    `protected Reference` | `ref` Deprecated. since 1.7. The user should not be directly referencing variable. Please use `getRefid()` instead.

    - ### Fields inherited from class org.apache.tools.ant.ProjectComponent

      `description, location, project`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `DataType()`

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `protected void` | `checkAttributesAllowed()` check that it is ok to set attributes, i.e that no reference is defined
    `protected void` | `checkChildrenAllowed()` check that it is ok to add children, i.e that no reference is defined
    `protected BuildException` | `circularReference()` Creates an exception that indicates the user has generated a loop of data types referencing each other.
    `java.lang.Object` | `clone()`
    `protected void` | `dieOnCircularReference()` Convenience method.
    `protected void` | `dieOnCircularReference(Project p)` Convenience method.
    `protected void` | `dieOnCircularReference(java.util.Stack<java.lang.Object> stack, Project project)` Check to see whether any DataType we hold references to is included in the Stack (which holds all DataType instances that directly or indirectly reference this instance, including this instance itself).
    `protected java.lang.Object` | `getCheckedRef()` Performs the check for circular references and returns the referenced object.
    `protected <T> T` | `getCheckedRef(java.lang.Class<T> requiredClass, java.lang.String dataTypeName)` Performs the check for circular references and returns the referenced object.
    `protected <T> T` | `getCheckedRef(java.lang.Class<T> requiredClass, java.lang.String dataTypeName, Project project)` Performs the check for circular references and returns the referenced object.
    `protected java.lang.Object` | `getCheckedRef(Project p)` Performs the check for circular references and returns the referenced object.
    `protected java.lang.String` | `getDataTypeName()` Gets as descriptive as possible a name used for this datatype instance.
    `Reference` | `getRefid()` get the reference set on this object
    `static void` | `invokeCircularReferenceCheck(DataType dt, java.util.Stack<java.lang.Object> stk, Project p)` Allow DataTypes outside org.apache.tools.ant.types to indirectly call dieOnCircularReference on nested DataTypes.
    `protected boolean` | `isChecked()` The flag that is used to indicate that circular references have been checked.
    `boolean` | `isReference()` Has the refid attribute of this element been set?
    `protected BuildException` | `noChildrenAllowed()` Creates an exception that indicates that this XML element must not have child elements if the refid attribute is set.
    `static void` | `pushAndInvokeCircularReferenceCheck(DataType dt, java.util.Stack<java.lang.Object> stk, Project p)` Allow DataTypes outside org.apache.tools.ant.types to indirectly call dieOnCircularReference on nested DataTypes.
    `protected void` | `setChecked(boolean checked)` Set the flag that is used to indicate that circular references have been checked.
    `void` | `setRefid(Reference ref)` Set the value of the refid attribute.
    `protected BuildException` | `tooManyAttributes()` Creates an exception that indicates that refid has to be the only attribute if it is set.
    `java.lang.String` | `toString()` Basic DataType toString().

    - ### Methods inherited from class org.apache.tools.ant.ProjectComponent

      `getDescription, getLocation, getProject, log, log, setDescription, setLocation, setProject`

    - ### Methods inherited from class java.lang.Object

      `equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

- - ### Field Detail

    - #### ref

          protected Reference ref

      Deprecated. since 1.7. The user should not be directly referencing variable. Please use `getRefid()` instead.
      Value to the refid attribute.

    - #### checked

          protected boolean checked

      Deprecated. since 1.7. The user should not be directly referencing variable. Please use `setChecked(boolean)` or `isChecked()` instead.
      Are we sure we don't hold circular references?

      Subclasses are responsible for setting this value to false if we'd need to investigate this condition (usually because a child element has been added that is a subclass of DataType).

  - ### Constructor Detail

    - #### DataType

          public DataType()

  - ### Method Detail

    - #### isReference

          public boolean isReference()

      Has the refid attribute of this element been set?
      Returns:
        true if the refid attribute has been set

    - #### setRefid

          public void setRefid(Reference ref)

      Set the value of the refid attribute.

      Subclasses may need to check whether any other attributes have been set as well or child elements have been created and thus override this method. if they do the must call `super.setRefid`.

      Parameters:
        `ref` - the reference to use

    - #### getDataTypeName

          protected java.lang.String getDataTypeName()

      Gets as descriptive as possible a name used for this datatype instance.
      Returns:
        `String` name.

    - #### dieOnCircularReference

          protected void dieOnCircularReference()

      Convenience method.
      Since:
        Ant 1.7

    - #### dieOnCircularReference

          protected void dieOnCircularReference(Project p)

      Convenience method.
      Parameters:
        `p` - the Ant Project instance against which to resolve references.
      Since:
        Ant 1.7

    - #### dieOnCircularReference

          protected void dieOnCircularReference(java.util.Stack<java.lang.Object> stack,
                                    Project project)
                                         throws BuildException

      Check to see whether any DataType we hold references to is included in the Stack (which holds all DataType instances that directly or indirectly reference this instance, including this instance itself).

      If one is included, throw a BuildException created by `circularReference`.

      This implementation is appropriate only for a DataType that cannot hold other DataTypes as children.

      The general contract of this method is that it shouldn't do anything if ``checked`` is true and set it to true on exit.

      Parameters:
        `stack` - the stack of references to check.
        `project` - the project to use to dereference the references.
      Throws:
        `BuildException` - on error.

    - #### invokeCircularReferenceCheck

          public static void invokeCircularReferenceCheck(DataType dt,
                                          java.util.Stack<java.lang.Object> stk,
                                          Project p)

      Allow DataTypes outside org.apache.tools.ant.types to indirectly call dieOnCircularReference on nested DataTypes.
      Parameters:
        `dt` - the DataType to check.
        `stk` - the stack of references to check.
        `p` - the project to use to dereference the references.
      Throws:
        `BuildException` - on error.
      Since:
        Ant 1.7

    - #### pushAndInvokeCircularReferenceCheck

          public static void pushAndInvokeCircularReferenceCheck(DataType dt,
                                                 java.util.Stack<java.lang.Object> stk,
                                                 Project p)

      Allow DataTypes outside org.apache.tools.ant.types to indirectly call dieOnCircularReference on nested DataTypes.

      Pushes dt on the stack, runs dieOnCircularReference and pops it again.

      Parameters:
        `dt` - the DataType to check.
        `stk` - the stack of references to check.
        `p` - the project to use to dereference the references.
      Throws:
        `BuildException` - on error.
      Since:
        Ant 1.8.0

    - #### getCheckedRef

          protected java.lang.Object getCheckedRef()

      Performs the check for circular references and returns the referenced object.
      Returns:
        the dereferenced object.
      Throws:
        `BuildException` - if the reference is invalid (circular ref, wrong class, etc).
      Since:
        Ant 1.7

    - #### getCheckedRef

          protected java.lang.Object getCheckedRef(Project p)

      Performs the check for circular references and returns the referenced object.
      Parameters:
        `p` - the Ant Project instance against which to resolve references.
      Returns:
        the dereferenced object.
      Throws:
        `BuildException` - if the reference is invalid (circular ref, wrong class, etc).
      Since:
        Ant 1.7

    - #### getCheckedRef

          protected <T> T getCheckedRef(java.lang.Class<T> requiredClass,
                            java.lang.String dataTypeName)

      Performs the check for circular references and returns the referenced object.
      Parameters:
        `requiredClass` - the class that this reference should be a subclass of.
        `dataTypeName` - the name of the datatype that the reference should be (error message use only).
      Returns:
        the dereferenced object.
      Throws:
        `BuildException` - if the reference is invalid (circular ref, wrong class, etc).

    - #### getCheckedRef

          protected <T> T getCheckedRef(java.lang.Class<T> requiredClass,
                            java.lang.String dataTypeName,
                            Project project)

      Performs the check for circular references and returns the referenced object. This version allows the fallback Project instance to be specified.
      Parameters:
        `requiredClass` - the class that this reference should be a subclass of.
        `dataTypeName` - the name of the datatype that the reference should be (error message use only).
        `project` - the fallback Project instance for dereferencing.
      Returns:
        the dereferenced object.
      Throws:
        `BuildException` - if the reference is invalid (circular ref, wrong class, etc), or if `project` is `null`.
      Since:
        Ant 1.7

    - #### tooManyAttributes

          protected BuildException tooManyAttributes()

      Creates an exception that indicates that refid has to be the only attribute if it is set.
      Returns:
        the exception to throw

    - #### noChildrenAllowed

          protected BuildException noChildrenAllowed()

      Creates an exception that indicates that this XML element must not have child elements if the refid attribute is set.
      Returns:
        the exception to throw

    - #### circularReference

          protected BuildException circularReference()

      Creates an exception that indicates the user has generated a loop of data types referencing each other.
      Returns:
        the exception to throw

    - #### isChecked

          protected boolean isChecked()

      The flag that is used to indicate that circular references have been checked.
      Returns:
        true if circular references have been checked

    - #### setChecked

          protected void setChecked(boolean checked)

      Set the flag that is used to indicate that circular references have been checked.
      Parameters:
        `checked` - if true, if circular references have been checked

    - #### getRefid

          public Reference getRefid()

      get the reference set on this object
      Returns:
        the reference or null

    - #### checkAttributesAllowed

          protected void checkAttributesAllowed()

      check that it is ok to set attributes, i.e that no reference is defined
      Throws:
        `BuildException` - if not allowed
      Since:
        Ant 1.6

    - #### checkChildrenAllowed

          protected void checkChildrenAllowed()

      check that it is ok to add children, i.e that no reference is defined
      Throws:
        `BuildException` - if not allowed
      Since:
        Ant 1.6

    - #### toString

          public java.lang.String toString()

      Basic DataType toString().
      Overrides:
        `toString` in class `java.lang.Object`
      Returns:
        this DataType formatted as a String.

    - #### clone

          public java.lang.Object clone()
                                 throws java.lang.CloneNotSupportedException

      Overrides:
        `clone` in class `ProjectComponent`
      Returns:
        a shallow copy of this DataType.
      Throws:
        `java.lang.CloneNotSupportedException` - if there is a problem.
      Since:
        Ant 1.7